
let cut_down = Behavior({
    data:{
        countDownDay:'00',
        countDownHour:'00',
        countDownMinute:"00",
        countDownSecond:'00',
        interval:null,
        distance:""
    },
    methods:{
        startTimer(currentstartTimer) {
            let day = "", hour = '', minute = '',second = "";
            let that = this;
            clearInterval(this.data.interval);
            this.setData({
                distance:currentstartTimer
            })
            this.data.interval = setInterval(function() {
                if (that.data.distance <= 0) {
                    clearInterval(that.data.interval);
                }
                // 秒数
                day = Math.floor(that.data.distance/1000/60/60/24).toString();
               hour = Math.floor(that.data.distance/1000/60/60%24).toString();
                minute = Math.floor(that.data.distance/1000/60%60).toString();
                second = Math.floor(that.data.distance/1000%60).toString();
                day = day.length == 1? ('0' + day) : day;
                hour = hour.length == 1? ('0' + hour) : hour;
                minute = minute.length == 1? ('0' + minute) : minute;
                second = second.length == 1? ('0' + second) : second;
                that.setData({
                    countDownDay : day,
                    countDownHour : hour,
                    countDownMinute : minute,
                    countDownSecond : second,
                    distance : that.data.distance - 1000
                })
            }, 1000);
        }
    } 
})
export {
    cut_down 
}